﻿namespace Sidvall.WorkItemManager.Model
{
    public abstract partial class DataPortalBase : global::Sidvall.WorkItemManager.Model.IDataPortalManager
    {
        #region Public Members

        #region ResourceFactory

        private global::Sidvall.Data.IResourceFactory _ResourceFactory;
        public global::Sidvall.Data.IResourceFactory ResourceFactory
        {
            get
            {
                if (_ResourceFactory != null)
                    return _ResourceFactory;
                return this.DataPortalManager.ResourceFactory;
            }
            protected set
            {
                _ResourceFactory = value;
            }
        }

        #endregion
        #region GenericDataPortal

        private global::Sidvall.WorkItemManager.Model.GenericDataPortal _GenericDataPortal;
        public global::Sidvall.WorkItemManager.Model.GenericDataPortal GenericDataPortal
        {
            get
            {
                if (_GenericDataPortal != null)
                    return _GenericDataPortal;
                return this.DataPortalManager.GenericDataPortal;
            }
            protected set
            {
                _GenericDataPortal = value;
            }
        }

        #endregion
        #region GenericEntityFacade

        private global::Sidvall.WorkItemManager.Data.Model.GenericEntityFacade _GenericEntityFacade;
        public global::Sidvall.WorkItemManager.Data.Model.GenericEntityFacade GenericEntityFacade
        {
            get
            {
                if (_GenericEntityFacade != null)
                    return _GenericEntityFacade;
                return this.DataPortalManager.GenericEntityFacade;
            }
            protected set
            {
                _GenericEntityFacade = value;
            }
        }

        #endregion
        #region LocalDataPortal

        private global::Sidvall.Business.IDataPortal _LocalDataPortal;
        public global::Sidvall.Business.IDataPortal LocalDataPortal
        {
            get
            {
                if (_LocalDataPortal != null)
                    return _LocalDataPortal;
                return this.DataPortalManager.LocalDataPortal;
            }
            protected set
            {
                _LocalDataPortal = value;
            }
        }

        #endregion
        #region RemoteDataPortal

        private global::Sidvall.Business.IDataPortal _RemoteDataPortal;
        public global::Sidvall.Business.IDataPortal RemoteDataPortal
        {
            get
            {
                if (_RemoteDataPortal != null)
                    return _RemoteDataPortal;
                return this.DataPortalManager.RemoteDataPortal;
            }
            protected set
            {
                _RemoteDataPortal = value;
            }
        }

        #endregion
        
        #endregion
        #region Private Members

        private global::Sidvall.WorkItemManager.Model.IDataPortalManager DataPortalManager { get; set; }

        #endregion
        #region Constructors

        protected DataPortalBase(global::Sidvall.WorkItemManager.Model.IDataPortalManager dataPortalManager)
        {
            this.DataPortalManager = dataPortalManager;
        }
        protected DataPortalBase(global::Sidvall.Data.IResourceFactory resourceFactory, global::Sidvall.Business.IDataPortal dataPortal)
        {
            this.ResourceFactory = resourceFactory;
            this.GenericDataPortal = new global::Sidvall.WorkItemManager.Model.GenericDataPortal(this, true);
            this.GenericEntityFacade = new global::Sidvall.WorkItemManager.Data.Model.GenericEntityFacade(this.ResourceFactory);
            this.LocalDataPortal = dataPortal;
        }
        protected DataPortalBase(global::Sidvall.Data.IResourceFactory resourceFactory, global::Sidvall.WorkItemManager.Model.IDataPortalFactory localDataPortalFactory, global::Sidvall.WorkItemManager.Model.IDataPortalFactory remoteDataPortalFactory)
        {
            this.ResourceFactory = resourceFactory;
            this.GenericDataPortal = new global::Sidvall.WorkItemManager.Model.GenericDataPortal(this, false);
            this.GenericEntityFacade = new global::Sidvall.WorkItemManager.Data.Model.GenericEntityFacade(this.ResourceFactory);
            this.LocalDataPortal = localDataPortalFactory.GetDataPortal(this);
            if (remoteDataPortalFactory != null)
                this.RemoteDataPortal = remoteDataPortalFactory.GetDataPortal(this);
        }
        
        #endregion
    }
}